package com.kun.gulimall.guliproduct.config;

import com.aliyun.oss.ClientConfiguration;
import com.aliyun.oss.OSSClient;
import com.aliyun.oss.common.auth.DefaultCredentialProvider;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class OssConfig {

    @Value("${alibaba.cloud.access-key}")
    private String accessKey;

    @Value("${alibaba.cloud.secret-key}")
    private String secretKey;

    @Value("${alibaba.cloud.oss.endpoint}")
    private String endpoint;

    @Bean
    public OSSClient ossClient() {
        DefaultCredentialProvider credsProvider = new DefaultCredentialProvider(accessKey, secretKey);
        // 创建 ClientConfiguration（可定制参数）
        ClientConfiguration config = new ClientConfiguration();
        config.setConnectionTimeout(5000);  // 连接超时时间（毫秒）
        config.setMaxErrorRetry(3);         // 最大重试次数
        config.setSocketTimeout(10000);     // 读写超时
        return new OSSClient(endpoint, credsProvider, config);
    }

}
